using System;
using System.IO;
using ns11;

namespace ns9
{
	internal class Class52 : Interface2, Interface5
	{
		private class Class53
		{
			private Struct12 struct12_0;

			private Struct12 struct12_1;

			private Struct14[] struct14_0 = new Struct14[16];

			private Struct14[] struct14_1 = new Struct14[16];

			private Struct14 struct14_2 = new Struct14(8);

			private uint uint_0;

			public void method_0(uint uint_1)
			{
				for (uint num = uint_0; num < uint_1; num++)
				{
					struct14_0[num] = new Struct14(3);
					struct14_1[num] = new Struct14(3);
				}
				uint_0 = uint_1;
			}

			public void method_1()
			{
				struct12_0.method_1();
				for (uint num = 0u; num < uint_0; num++)
				{
					struct14_0[num].method_0();
					struct14_1[num].method_0();
				}
				struct12_1.method_1();
				struct14_2.method_0();
			}

			public uint method_2(Class63 class63_0, uint uint_1)
			{
				if (struct12_0.method_2(class63_0) == 0)
				{
					return struct14_0[uint_1].method_1(class63_0);
				}
				uint num = 8u;
				if (struct12_1.method_2(class63_0) == 0)
				{
					return num + struct14_1[uint_1].method_1(class63_0);
				}
				num += 8;
				return num + struct14_2.method_1(class63_0);
			}
		}

		internal class Class54
		{
			private struct Struct9
			{
				private Struct12[] struct12_0;

				public void method_0()
				{
					struct12_0 = new Struct12[768];
				}

				public void method_1()
				{
					for (int i = 0; i < 768; i++)
					{
						struct12_0[i].method_1();
					}
				}

				public byte method_2(Class63 class63_0)
				{
					uint num = 1u;
					do
					{
						num = (num << 1) | struct12_0[num].method_2(class63_0);
					}
					while (num < 256);
					return (byte)num;
				}

				public byte method_3(Class63 class63_0, byte byte_0)
				{
					uint num = 1u;
					do
					{
						uint num2 = (uint)(byte_0 >> 7) & 1u;
						byte_0 = (byte)(byte_0 << 1);
						uint num3 = struct12_0[(1 + num2 << 8) + num].method_2(class63_0);
						num = (num << 1) | num3;
						if (num2 != num3)
						{
							while (num < 256)
							{
								num = (num << 1) | struct12_0[num].method_2(class63_0);
							}
							break;
						}
					}
					while (num < 256);
					return (byte)num;
				}
			}

			private Struct9[] struct9_0;

			private int int_0;

			private int int_1;

			private uint uint_0;

			public void method_0(int int_2, int int_3)
			{
				if (struct9_0 == null || int_0 != int_3 || int_1 != int_2)
				{
					int_1 = int_2;
					uint_0 = (uint)((1 << int_2) - 1);
					int_0 = int_3;
					uint num = (uint)(1 << int_0 + int_1);
					struct9_0 = new Struct9[num];
					for (uint num2 = 0u; num2 < num; num2++)
					{
						struct9_0[num2].method_0();
					}
				}
			}

			public void method_1()
			{
				uint num = (uint)(1 << int_0 + int_1);
				for (uint num2 = 0u; num2 < num; num2++)
				{
					struct9_0[num2].method_1();
				}
			}

			private uint method_2(uint uint_1, byte byte_0)
			{
				return ((uint_1 & uint_0) << int_0) + (uint)(byte_0 >> 8 - int_0);
			}

			public byte method_3(Class63 class63_0, uint uint_1, byte byte_0)
			{
				return struct9_0[method_2(uint_1, byte_0)].method_2(class63_0);
			}

			public byte method_4(Class63 class63_0, uint uint_1, byte byte_0, byte byte_1)
			{
				return struct9_0[method_2(uint_1, byte_0)].method_3(class63_0, byte_1);
			}
		}

		private Class61 class61_0 = new Class61();

		private Class63 class63_0 = new Class63();

		private Struct12[] struct12_0 = new Struct12[192];

		private Struct12[] struct12_1 = new Struct12[12];

		private Struct12[] struct12_2 = new Struct12[12];

		private Struct12[] struct12_3 = new Struct12[12];

		private Struct12[] struct12_4 = new Struct12[12];

		private Struct12[] struct12_5 = new Struct12[192];

		private Struct14[] struct14_0 = new Struct14[4];

		private Struct12[] struct12_6 = new Struct12[114];

		private Struct14 struct14_1 = new Struct14(4);

		private Class53 class53_0 = new Class53();

		private Class53 class53_1 = new Class53();

		private Class54 class54_0 = new Class54();

		private uint uint_0;

		private uint uint_1;

		private uint uint_2;

		public Class52()
		{
			uint_0 = uint.MaxValue;
			for (int i = 0; i < 4L; i++)
			{
				struct14_0[i] = new Struct14(6);
			}
		}

		private void method_0(uint uint_3)
		{
			if (uint_0 != uint_3)
			{
				uint_0 = uint_3;
				uint_1 = Math.Max(uint_0, 1u);
				uint uint_4 = Math.Max(uint_1, 4096u);
				class61_0.method_0(uint_4);
			}
		}

		private void method_1(int int_0, int int_1)
		{
			if (int_0 > 8)
			{
				throw new Exception1();
			}
			if (int_1 > 8)
			{
				throw new Exception1();
			}
			class54_0.method_0(int_0, int_1);
		}

		private void method_2(int int_0)
		{
			if (int_0 > 4)
			{
				throw new Exception1();
			}
			uint num = (uint)(1 << int_0);
			class53_0.method_0(num);
			class53_1.method_0(num);
			uint_2 = num - 1;
		}

		private void method_3(Stream stream_0, Stream stream_1)
		{
			class63_0.method_0(stream_0);
			class61_0.method_2(stream_1);
			for (uint num = 0u; num < 12; num++)
			{
				for (uint num2 = 0u; num2 <= uint_2; num2++)
				{
					uint num3 = (num << 4) + num2;
					struct12_0[num3].method_1();
					struct12_5[num3].method_1();
				}
				struct12_1[num].method_1();
				struct12_2[num].method_1();
				struct12_3[num].method_1();
				struct12_4[num].method_1();
			}
			class54_0.method_1();
			for (uint num = 0u; num < 4; num++)
			{
				struct14_0[num].method_0();
			}
			for (uint num = 0u; num < 114; num++)
			{
				struct12_6[num].method_1();
			}
			class53_0.method_1();
			class53_1.method_1();
			struct14_1.method_0();
		}

		public void imethod_0(Stream stream_0, Stream stream_1, long long_0, long long_1, Interface1 interface1_0)
		{
			method_3(stream_0, stream_1);
			Class51.Struct8 @struct = default(Class51.Struct8);
			@struct.method_0();
			uint num = 0u;
			uint num2 = 0u;
			uint num3 = 0u;
			uint num4 = 0u;
			ulong num5 = 0uL;
			if (0uL < (ulong)long_1)
			{
				if (struct12_0[@struct.uint_0 << 4].method_2(class63_0) != 0)
				{
					throw new Exception0();
				}
				@struct.method_1();
				byte byte_ = class54_0.method_3(class63_0, 0u, 0);
				class61_0.method_6(byte_);
				num5++;
			}
			while (num5 < (ulong)long_1)
			{
				uint num6 = (uint)(int)num5 & uint_2;
				if (struct12_0[(@struct.uint_0 << 4) + num6].method_2(class63_0) == 0)
				{
					byte byte_2 = class61_0.method_7(0u);
					byte byte_3 = (@struct.method_5() ? class54_0.method_3(class63_0, (uint)num5, byte_2) : class54_0.method_4(class63_0, (uint)num5, byte_2, class61_0.method_7(num)));
					class61_0.method_6(byte_3);
					@struct.method_1();
					num5++;
					continue;
				}
				uint num8;
				if (struct12_1[@struct.uint_0].method_2(class63_0) == 1)
				{
					if (struct12_2[@struct.uint_0].method_2(class63_0) == 0)
					{
						if (struct12_5[(@struct.uint_0 << 4) + num6].method_2(class63_0) == 0)
						{
							@struct.method_4();
							class61_0.method_6(class61_0.method_7(num));
							num5++;
							continue;
						}
					}
					else
					{
						uint num7;
						if (struct12_3[@struct.uint_0].method_2(class63_0) == 0)
						{
							num7 = num2;
						}
						else
						{
							if (struct12_4[@struct.uint_0].method_2(class63_0) == 0)
							{
								num7 = num3;
							}
							else
							{
								num7 = num4;
								num4 = num3;
							}
							num3 = num2;
						}
						num2 = num;
						num = num7;
					}
					num8 = class53_1.method_2(class63_0, num6) + 2;
					@struct.method_3();
				}
				else
				{
					num4 = num3;
					num3 = num2;
					num2 = num;
					num8 = 2 + class53_0.method_2(class63_0, num6);
					@struct.method_2();
					uint num9 = struct14_0[Class51.smethod_0(num8)].method_1(class63_0);
					if (num9 >= 4)
					{
						int num10 = (int)((num9 >> 1) - 1);
						num = (2 | (num9 & 1)) << num10;
						if (num9 < 14)
						{
							num += Struct14.smethod_0(struct12_6, num - num9 - 1, class63_0, num10);
						}
						else
						{
							num += class63_0.method_7(num10 - 4) << 4;
							num += struct14_1.method_2(class63_0);
						}
					}
					else
					{
						num = num9;
					}
				}
				if (num < num5 && num < uint_1)
				{
					class61_0.method_5(num, num8);
					num5 += num8;
					continue;
				}
				if (num == uint.MaxValue)
				{
					break;
				}
				throw new Exception0();
			}
			class61_0.method_4();
			class61_0.method_3();
			class63_0.method_1();
		}

		public void imethod_1(byte[] byte_0)
		{
			if (byte_0.Length < 5)
			{
				throw new Exception1();
			}
			int int_ = (int)byte_0[0] % 9;
			int num = (int)byte_0[0] / 9;
			int int_2 = num % 5;
			int num2 = num / 5;
			if (num2 > 4)
			{
				throw new Exception1();
			}
			uint num3 = 0u;
			for (int i = 0; i < 4; i++)
			{
				num3 += (uint)(byte_0[1 + i] << i * 8);
			}
			method_0(num3);
			method_1(int_2, int_);
			method_2(num2);
		}
	}
}
